/* ========================================================================= */
/* ------------------------------------------------------------------------- */
/*!
  \file			pglnpattern.h
  \date			Jun 2012
  \author		TNick

  \brief		Contains the definition for PgLnPattern class


*//*


 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Please read COPYING and README files in root folder
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
#ifndef __PGLNPATTERN_INC__
#define __PGLNPATTERN_INC__
//
//
//
//
/*  INCLUDES    ------------------------------------------------------------ */

#include	<qnamespace.h>
#include	<QVector>
#include	<geomcpp.h>
#include	<cpg/logic/pgcharacteristic.h>

/*  INCLUDES    ============================================================ */
//
//
//
//
/*  CLASS    --------------------------------------------------------------- */

class	QStringList;
class	QDomElement;

namespace	cpg		{

class	CpgDoc;
class	QPen;
class	PgCtx;

/**
*	@brief	Represents a custom line pattern in CpgDoc
*/
class PgLnPattern	: public PgCharacteristic			{
	BBM_TRACK( PgLnPattern );

	//
	//
	//
	//
	/*  DEFINITIONS    ----------------------------------------------------- */

public:


#	define	pattQtPgExchange	0x1000
#	define	pattFromPgToQt(c)	(Qt::PenStyle)(c+pattQtPgExchange)
#	define	pattFromQtToPg(c)	(PgLnPattern::Id)(c-pattQtPgExchange)



	/**
	*	@brief	representation of a line pattern in Play-Ground
	*
	*	Special codes are negative; zero and positive numbers are used
	*	as indices in the CpgDoc hosted array of patterns (only the document
	*	hosts a PgLnPattern, the other entities use Id's.
	*
	*	To convert between a Id and a Qt::PenStyle use the
	*	pattFromPgToQt macro; the other way arround is done using
	*	pattFromQtToPg.
	*/
	enum			Id				{
		NOPEN = Qt::NoPen-pattQtPgExchange,
		SOLID = Qt::SolidLine-pattQtPgExchange,
		DASH = Qt::DashLine-pattQtPgExchange,
		DOT = Qt::DotLine-pattQtPgExchange,
		DASHDOT =  Qt::DashDotLine-pattQtPgExchange,
		DASHDOTDOT = Qt::DashDotDotLine-pattQtPgExchange,

		/* special codes */
		BYLAYER = PgCharacteristic::BYLAYER,
		BYBLOCK = PgCharacteristic::BYBLOCK

	};


	/**
	*	@brief	the container for the list of line pattern (in a document, for example)
	*/
	typedef	QList<Id>			List;


	/*  DEFINITIONS    ===================================================== */
	//
	//
	//
	//
	/*  DATA    ------------------------------------------------------------ */

private:


	/**
	*	@brief	the pattern for the pen
	*
	*	The pattern must be specified as an even number of positive entries
	*	where the entries 1, 3, 5... are the dashes and 2, 4, 6... are
	*	the spaces.
	*/
	QVector<qreal>		dashes_;


	/**
	*	@brief	offset for the pattern
	*/
	qreal				off_;


	/*  DATA    ============================================================ */
	//
	//
	//
	//
	/*  FUNCTIONS    ------------------------------------------------------- */

public:


	/**
	*	@brief	constructor;
	*/
	PgLnPattern				( CpgDoc * doc );


	/**
	*	@brief	destructor;
	*/
	~PgLnPattern			( void );


	/**
	*	@brief	report internally stored pattern
	*/
	inline QVector<qreal>	pattern			( void )
	{ return dashes_; }


	/**
	*	@brief	change internally stored pattern
	*/
	inline void				setPattern		( QVector<qreal> new_val )
	{ dashes_ = new_val; }


	/**
	*	@brief	report offset
	*/
	inline qreal			offset			( void )
	{ return off_; }


	/**
	*	@brief	change offset
	*/
	inline void				setOffset		( qreal new_val )
	{ off_ = new_val; }


	/**
	*	@brief	clone this characteristic in target ocument
	*/
	PgLnPattern *			clone			( CpgDoc * destin, int & idx );





	/* ******************************************************************* */
	/** @name 	Management methods                                         */
	/* ******************************************************************* */
	///@{


	/**
	*	@brief	tell if the id is inside allowed range
	*/
	static bool				isIdValid			( CpgDoc * doc, int id );


	/**
	*	@brief	get the sequence of points and spaces that represent this pattern
	*/
	static QVector<qreal>	explicitPattern		(
			PgCtx *				ctx,
			int					id
			);


	/**
	*	@brief	save a pattern as a XML attribute for provided element
	*/
	static void				asXML				(
			PgCtx *				ctx,
			Id					id,
			QDomElement &		dest
			);


	/**
	*	@brief	copies a color from source document to target document
	*
	*	@return	the id to be used in destination document
	*/
	static int				copy			(
			CpgDoc *				source,
			CpgDoc *				destin,
			int					value
			);


	///@}
	/* ******************************************************************* */



	/* ******************************************************************* */
	/** @name 	String related nethods                                     */
	/* ******************************************************************* */
	///@{


protected:


	/**
	*	@brief	get the name that coresponds to given id
	*/
	static QString			nameForId		( Id id );


	/**
	*	@brief	get the names and coresponding id for all codes
	*/
	static void				nameAndId		(
			QStringList &			name_list,
			QList<int> &			id_list
			);


public:


	/**
	*	@brief	get the string that represents this pattern
	*/
	static QString			asString		( CpgDoc * doc, int id );


	///@}
	/* ******************************************************************* */


	/*  FUNCTIONS    ======================================================= */
	//
	//
	//
	//

};	/*	class PgLnPattern	*/

/*  CLASS    =============================================================== */
//
//
//
//

}	//	namespace	cpg

#endif // __PGLNPATTERN_INC__
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
